// 例子13

{
    // (1) 交换变量的值
    let x = 1;
    let y = 2;
    console.log(`交换前：x=${x}  y=${y}`);
    [x, y] = [y, x];
    console.log(`交换后：x=${x}  y=${y}`);
}

console.log('----------------------------------')

{
    // (2) 从函数返回多个值
    // 返回一个数组
    function example1() {
        return [1, 2, 3];
    }
    let [a, b, c] = example1();
    console.log(`a=${a}  b=${b}  c=${c}`);

    // 返回一个对象
    function example2() {
        return {
            foo: 1,
            bar: 2
        };
    }
    let { foo, bar } = example2();
    console.log(`foo=${foo}  bar=${bar}`);
}

console.log('----------------------------------')

{
    // (3) 函数参数的定义和默认值
    // 参数是一组有次序的值
    function f1([x, y, z]) {
        //...
    }
    f1([1, 2, 3]);

    // 参数是一组无次序的值
    function f2({ x, y, z }) {
        //...
    }
    f2({z: 3, y: 2, x: 1});

    // 函数参数默认值
    try {
        jQuery.ajax = function (url, {
            async = true,
            beforeSend = function () {},
            cache = true,
            complete = function () {},
            crossDomain = false,
            global = true,
            // ... more config
        } = {}) {
        // ... do stuff
        };
    } catch(e) {
        console.log('伪代码')
    }

}

console.log('----------------------------------')

{
    let jsonData = {
        id: 42,
        status: "OK",
        data: [867, 5309]
    };

    let { id, status, data: number } = jsonData;
    console.log(id, status, number);	// 42 "OK" [867, 5309]
}

console.log('----------------------------------')

{
    try {
        const { SourceMapConsumer, SourceNode } = require("source-map");
    } catch(e) {
        console.log('伪代码')
    }

}

